package com.kingdee.pda.ui.sn_query_edit;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.kingdee.pda.R;
import com.kingdee.pda.adapter.AbsBaseAdapter;
import com.kingdee.pda.callback.MyOnScrollChangedListener;
import com.kingdee.pda.ui.widget.CustomHScrollView;
import com.kingdee.pda.util.CommonUtil;
import com.kingdee.pda.util.ViewHolder;

/**
 * Created by dlj
 * DATE 2021/12/10
 * TIME 14:49
 */
public class SnQueryListAdapter extends AbsBaseAdapter<ItemSNInfoVo> {

    private CustomHScrollView customHScrollView;

    public SnQueryListAdapter(Context context, CustomHScrollView customHScrollView) {
        super(context);
        this.customHScrollView = customHScrollView;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.adapter_item_sn_list, parent, false);
        }

        TextView tv_itemSkuNumber = ViewHolder.get(convertView, R.id.tv_itemSkuNumber);
        TextView tv_itemName = ViewHolder.get(convertView, R.id.tv_itemName);
        TextView tv_status = ViewHolder.get(convertView, R.id.tv_status);
        TextView tv_snNo = ViewHolder.get(convertView, R.id.tv_snNo);
        TextView tv_serialNo = ViewHolder.get(convertView, R.id.tv_serialNo);
        TextView tv_bSNNo = ViewHolder.get(convertView, R.id.tv_bSNNo);
        TextView tv_bSerialNo = ViewHolder.get(convertView, R.id.tv_bSerialNo);
        TextView tv_ownerName = ViewHolder.get(convertView, R.id.tv_ownerName);

        CustomHScrollView contentScorllView = convertView.findViewById(R.id.h_scrollView);
        customHScrollView.AddOnScrollChangedListener(new MyOnScrollChangedListener(contentScorllView));

        ItemSNInfoVo snInfoVo = getData().get(position);
        tv_itemSkuNumber.setText(snInfoVo.getItemSkuNumber());
        tv_itemName.setText(snInfoVo.getItemName());
        tv_status.setText(CommonUtil.getStatusName(snInfoVo.getSnStatus()));
        tv_snNo.setText(snInfoVo.getSnNo());
        tv_serialNo.setText(snInfoVo.getSerialNo());
        tv_bSNNo.setText(snInfoVo.getbSNNo());
        tv_bSerialNo.setText(snInfoVo.getbSerialNo());
        tv_ownerName.setText(snInfoVo.getOwnerName());

        ViewHolder.get(convertView, R.id.tv_edit).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, SnEditActivity.class);
                intent.putExtra("data", snInfoVo);
                context.startActivity(intent);
            }
        });

        return convertView;
    }
}
